<template>
  <div>
    <h1>租房管理</h1>
    <!--租房信息查询-->
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="租客姓名">
        <el-input v-model="formInline.tenantName" placeholder="租客姓名" />
      </el-form-item>

      <el-form-item label="房源类型">
        <el-select v-model="formInline.signType" placeholder="房源类型">
          <el-option label="整租（分散式）" value="0" />
          <el-option label="合租（分散式）" value="1" />
          <el-option label="单身公寓（集中式）" value="2" />
        </el-select>
      </el-form-item>

      <el-form-item label="手机号码">
        <el-input v-model="formInline.tenantPhone" placeholder="手机号码" />
      </el-form-item>

      <el-form-item label="小区名称">
        <el-input v-model="formInline.roomName" placeholder="小区名称" />
      </el-form-item>

      <el-form-item label="起租日期">
        <el-date-picker v-model="formInline.startDate" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width: 100%;" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="TenantList()">查询</el-button>
        <el-button type="primary" @click="resetForm()">清空</el-button>
      </el-form-item>
    </el-form>
    <!--列表展示-->
    <el-table
      :data="tableData"
      border
      style="width: 100%"
    >
      <el-table-column
        prop="tenantName"
        label="租客姓名"
        width="100"
      />
      <el-table-column
        prop="tcfContract.cfContractNo"
        label="租房合同编号"
        width="200"
      />
      <el-table-column
        prop="tenantPhone"
        label="电话"
        width="150"
      />
      <el-table-column
        prop="tcfContract.roomName"
        label="房源信息"
        width="200"
      />
      <el-table-column
        label="房源类型"
        width="180"
      >
        <template slot-scope="scope">
          {{ scope.row.tcfContract.signType==0?'整租（分散式）':scope.row.tcfContract.signType==1?'合租（分散式）':'单身公寓（集中式）' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="tcfContract.startDate"
        label="起租日期"
        width="250"
      />
      <el-table-column
        prop="tcfContract.endDate"
        label="结束日期"
        width="250"
      />
      <el-table-column
        label="押付方式"
        width="250"
      >
        <template slot-scope="scope">
          押{{ scope.row.tcfContract.depositType }}付{{ scope.row.tcfContract.paymentType }}
        </template>
      </el-table-column>
      <el-table-column
        prop="tcfContract.deposit"
        label="押金"
        width="150"
      />
      <el-table-column
        prop="tcfContract.monthRent"
        label="租金"
        width="150"
      />
      <el-table-column
        prop="tcfContract.contractState"
        label="状态"
        width="180"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.tcfContract.contractState==1">
            <el-button type="info" size="mini">草稿</el-button>
          </span>
          <span v-if="scope.row.tcfContract.contractState==2">
            <el-button type="success" size="mini">已提交</el-button>
          </span>
          <span v-if="scope.row.tcfContract.contractState==3">
            <el-button type="primary" size="mini">已解约</el-button>
          </span>
          <span v-if="scope.row.tcfContract.contractState==4">
            <el-button type="danger" size="mini">已结束</el-button>
          </span>
          <span v-if="scope.row.tcfContract.contractState==9">
            <el-button type="danger" size="mini">作废</el-button>
          </span>
        </template>
      </el-table-column>
    </el-table>
    <!--分页展示-->
    <el-pagination
      background
      :current-page="pageNum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />

  </div>
</template>

<script>
export default {
  name: 'Tenant',
  data() {
    return {
      // 列表
      tableData: [],
      // 分页
      pageNum: 1,
      pageSize: 5,
      total: 0,
      // 查询
      formInline: {}
    }
  },
  created() {
    this.TenantList()
  },
  methods: {
    // 列表
    TenantList() {
      this.axios.get('http://localhost:9999/house-resource/tMTenant/list', {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          tenantName: this.formInline.tenantName,
          signType: this.formInline.signType,
          tenantPhone: this.formInline.tenantPhone,
          roomName: this.formInline.roomName,
          startDate: this.formInline.startDate
        }
      }).then((response) => {
        console.log(response.data)
        this.tableData = response.data.obj.list
        this.total = response.data.obj.total
      })
    },
    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.TenantList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.pageNum = val
      this.TenantList()
    },

    // 清空
    resetForm() {
      this.formInline = {}
    }
  }

}
</script>

